package com.lingnan.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lingnan.eduservice.entity.po.EduTeacherPO;
import com.lingnan.eduservice.entity.vo.EduCourseVO;
import com.lingnan.eduservice.entity.vo.EduTeacherLevelVO;
import com.lingnan.eduservice.mapper.EduTeacherMapper;
import com.lingnan.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author zzd
 * @since 2021-08-02
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacherPO> implements EduTeacherService {
    /**
     * 根据教师头衔分类(树形)
     *
     * @return
     */
    @Override
    public List<EduTeacherLevelVO> findTeacherByLevel() {

        // 查询所有教师信息
        List<EduTeacherPO> eduTeacherPOList = baseMapper.selectList(null);

        // 查询所有的头衔信息
        HashSet<Integer> levelSet = new HashSet<>();

        // 头衔信息(中转站)
        Integer id = null;

        // 当前头衔教师(中转站)
        EduTeacherPO eduTeacherPO = null;

        // 一对多头衔与教师信息(中转站)
        EduTeacherLevelVO eduTeacherLevelVO = null;

        // 存储当前level教师信息
        List<EduTeacherPO> eduTeacherVOList = null;

        // 根据头衔进行教师分类
        List<EduTeacherLevelVO> eduTeacherLevelVOList = new ArrayList<>(100);


        // 存储当前所有的头衔信息
        for (EduTeacherPO eduTeacher : eduTeacherPOList) {

            id = eduTeacher.getLevel();

            levelSet.add(id);

        }
        // 遍历当前所有level
        for (Integer level : levelSet) {

            // 创建对象用于中间存储
            eduTeacherLevelVO =  new EduTeacherLevelVO();

            eduTeacherVOList = new ArrayList<>(100);

            // 存储当前遍历到level
            eduTeacherLevelVO.setLevel(level);

            for (EduTeacherPO teacherPO : eduTeacherPOList) {
                // 获取当前遍历教师level
                Integer teacherLevel = teacherPO.getLevel();
                // 如果相同
                if(Objects.equals(level,teacherLevel)){
                    eduTeacherVOList.add(teacherPO);
                }
                eduTeacherLevelVO.setEduTeacherPOList(eduTeacherVOList);
            }
            // 存储到最终返回对象中
            eduTeacherLevelVOList.add(eduTeacherLevelVO);

        }


//        System.out.println(eduTeacherLevelVO);
//        for (EduTeacherLevelVO teacherLevelVO : eduTeacherLevelVOList) {
//            System.out.println(teacherLevelVO.getLevel());
//            System.out.println(teacherLevelVO.getEduTeacherPOList());
//            System.out.println("===============");
//        }

        return eduTeacherLevelVOList;
    }
}
